package com.cjg.netCode;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class udpURLTrue {
    public static void main(String[] args) throws Exception {
        //获取下载地址
        URL url = new URL("https://freetyst.nf.migu.cn/public/product5th/product35/2019/10/1219/2018%E5%B9%B401%E6%9C%8829%E6%97%A514%E7%82%B911%E5%88%86%E5%86%85%E5%AE%B9%E5%87%86%E5%85%A5%E7%A6%BE%E4%BF%A1%E9%A2%84%E7%95%99999%E9%A6%96/%E6%AD%8C%E6%9B%B2%E4%B8%8B%E8%BD%BD/MP3_40_16_Stero/69910406417.mp3?key=c70ade03b2b2b6a2&Tim=1615361397852&channelid=00&msisdn=8d836d8cde8f44a29314f73e044f541e&CI=699104064172600908000006799484&F=000009");
        //连接这个资源 http
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        //输入流接收数据
        InputStream inputStream = urlConnection.getInputStream();
        //输出问一个文件
        FileOutputStream fileOutputStream = new FileOutputStream("17.mp3");
        //默认步骤
        byte[] bytes = new byte[1024];
        int len;
        while ((len=inputStream.read(bytes))!=-1){
            fileOutputStream.write(bytes,0,len);
        }
    }
}
